import './public-path'
import './assets/main.css'
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
import App from './App.vue'
import router from './router'

let app
//判断是否为乾坤环境
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  createApp(App).use(router).use(createPinia()).mount('#app')
} else {
  renderWithQiankun({
    mount(props) {
      console.log('Vue 子应用接收到的 props:', props)
      const { actions } = props
      // 监听全局状态变化
      actions.onGlobalStateChange((state, prev) => {
        console.log('Vue 子应用监听到状态变化:', state, prev)
      })

      app = createApp(App)
      app.use(router).use(createPinia()).mount(props.container.querySelector('#app'))
    },
    bootstrap() {
      console.log('vue app bootstrap')
    },
    update() {
      console.log('vue app update')
    },
    unmount() {
      console.log('vue app unmount')
      app?.unmount()
    }
  })
}

// app.use(createPinia())
// app.use(router)

// app.mount('#app')

// function render(props = {}) {
//   const { container } = props
//   app.mount(container ? container.querySelector("#vueApp3") : "#app")
// }
// if (!window.POWERED_BY_QIANKUN__) {
//   render()
// }
// export async function bootstrap() {
//   console.log("[vue] vue app bootstraped")
// }
// export async function mount(props) {
//   console.log("[vue] props from main framework", props)
//   render(props)
// }
// export async function unmount() {
//   app.unmount()
// }
